package function;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;

/**
 * @ClassName: MyFunction
 * @Author: 王延
 * @Date: 2019/7/24 15:27
 * @Description :
 */
public class MyFunction {
    public static void main(String[] args) {
        //R apply(T t);
        Function<String, Integer> function = (String s) -> Integer.valueOf(s);
        System.out.println(function.apply("123"));
        List<Double> list = Arrays.asList(11.2, 98.7, 45.6, 76.3, 65.2);
        List<Double> results = wapperList(list, (Double score) -> score + 5);
        for (Double result : results) {
            System.out.println(result);
        }
    }

    public static <T, R> List<R> wapperList(List<T> list, Function<T, R> function) {
        List<R> results = new LinkedList<>();
        for (T t : list) {
            results.add(function.apply(t));
        }
        return results;
    }
}
